package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.BrandService;
import com.junzhiit.nengji.cms.web.vo.BrandAddVO;
import com.junzhiit.nengji.cms.web.vo.BrandEditVO;
import com.junzhiit.nengji.cms.web.vo.BrandVO;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/brand")
public class BrandController extends BaseController {

	@Autowired
	private BrandService brandService;

	@ApiOperation(value = "获取所有品牌")
	@RequestMapping(method = RequestMethod.GET)
	public Map<String, Object> findAll(String sessionId, DataTablesParamVO dtp, BrandVO brandVO) {
		AssertUtil.notBlank(sessionId, "sessionId is required.");
		return brandService.findAll(sessionId,dtp, brandVO);
	}

	@ApiOperation(value = "根据ID查询品牌")
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public ResultVO findById(@PathVariable String id) {
		AssertUtil.notBlank(id, "id is required.");
		return brandService.findById(id);
	}

	@ApiOperation(value = "创建品牌")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO add(String sessionId,BrandAddVO brandAddVO) {
		AssertUtil.notBlank(sessionId, "sessionId is required.");
		AssertUtil.notBlank(brandAddVO.getName(), "name is required.");
		return brandService.add(sessionId,brandAddVO);
	}

	@ApiOperation(value = "修改品牌")
	@RequestMapping(method = RequestMethod.PUT)
	public ResultVO update(BrandEditVO brandEditVO) {
		AssertUtil.notBlank(brandEditVO.getName(), "name is required.");
		return brandService.edit(brandEditVO);
	}

	@ApiOperation(value = "删除品牌")
	@RequestMapping(value = "/del", method = RequestMethod.PUT)
	public ResultVO delete(String id) {
		AssertUtil.notBlank(id, "id is required.");
		return brandService.delete(id);
	}

	@ApiOperation(value = "获取所有品牌下拉框")
	@RequestMapping(value = "/alls", method = RequestMethod.GET)
	public ResultVO findAlls(String sessionId) {
		AssertUtil.notBlank(sessionId, "sessionId is required.");
		return brandService.findAlls(sessionId);
	}

	@ApiOperation(value = "删除品牌图片")
	@RequestMapping(value = "/pic", method = RequestMethod.DELETE)
	public ResultVO delBrandPic(String id) {
		return brandService.delBrandPic(id);
	}

}
